//
//  WH_BaseViewController.m
//  App_6.23
//
//  Created by wanghao on 16/6/24.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_BaseViewController.h"
#import "AppDelegate.h"

@interface WH_BaseViewController (){
    
    WSProgressHUD *hub;
}

@end

@implementation WH_BaseViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:1];
    
}

- (void)createHub{
    
    hub = [[WSProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:hub];

}
- (void)hubShow{
    
    [hub showWithString:nil];
    
    
}
- (void)hubDismiss{
    
    [hub dismiss];
}

-(void)createBackBtn{
    
    //返回按钮
    UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.backgroundColor = [UIColor clearColor];
    [backButton setImage:[[UIImage imageNamed:@"btn_back_n"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    backButton.frame = CGRectMake(0, 0, 60*0.4, 90*0.4);
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    backButton.tintColor = [UIColor blackColor];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}
-(void)backButtonAction:(UIButton *)btn{
    
    CATransition *transition = [CATransition animation];
    transition.duration = 1.0f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    //立方块
    //    transition.type = @"cube";
    //收起
    //transition.type = @"suckEffect";
    // 页面旋转
    //    transition.type = @"oglFlip";
    //水波纹
        transition.type = @"rippleEffect";
    //翻页
    //    transition.type = @"pageCurl";
    //反向翻页
    //    transition.type = @"pageUnCurl";
    //开相机
    //    transition.type = @"cameraIrisHollowOpen";
    //关相机
     //   transition.type = @"cameraIrisHollowClose";
    //渐变消失
    //    transition.type = kCATransitionFade;
    //push
    //    transition.type = kCATransitionPush;
    
    //    transition.type = kCATransitionReveal;
    
    //   transition.type = kCATransitionMoveIn;
    
    transition.subtype = kCATransitionFromRight;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //写所有viewController都做的事
    [self createBackBtn];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];

    Reachability *r = [Reachability reachabilityWithHostName:@"http://y.bmstorez.com"];
    switch ([r currentReachabilityStatus]) {
        case NotReachable:
            NSLog(@"没有网");
            // 没有网络连接
            break;
        case ReachableViaWWAN:
            // 使用3G网络
            NSLog(@"使用3G网络");
            
            break;
        case ReachableViaWiFi:
            // 使用WiFi网络
            NSLog(@"使用WiFi网络");
            
            break;
    }

}
- (void)alertViewControllerWithTitle:(NSString *)title content:(NSString *)content {
    
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alertC addAction:action];
    [self presentViewController:alertC animated:YES completion:nil];
}

- (void)alertViewControllerWithTitle:(NSString *)title content:(NSString *)content block:(void(^)())block {
    
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        block();
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertC addAction:cancel];
    [alertC addAction:action];
    [self presentViewController:alertC animated:YES completion:nil];
}
-(void)createEmptylist{
    
    UIImageView *imgView = [[UIImageView alloc] init];
    imgView.tag = 30001;
    imgView.image = [UIImage imageNamed:@"cartImage"];
    imgView.userInteractionEnabled = YES;
    [self.view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view);
        make.top.equalTo(@0);
        make.height.equalTo(@(SCREEN_HEIGHT));
        
    }];
    
    //添加tap
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imBtnAction)];
    [imgView addGestureRecognizer:tap];
    
}
-(void)bringSubView{
    
    UIImageView *imageV = (UIImageView *)[self.view viewWithTag:30001];
    
    [self.view bringSubviewToFront:imageV];
}
- (void)imBtnAction{
    
    //UIApplication是系统单例,可以直接使用
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    
    appDelegate.tabbarMain.selectedIndex = 0;
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
